import%20marimo%0A%0A__generated_with%20%3D%20%220.17.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%2C%20%22ipynb%22%5D)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pytz%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20india_timezone%20%3D%20pytz.timezone(%22Asia%2FKolkata%22)%0A%20%20%20%20now%20%3D%20datetime.datetime.now(india_timezone)%0A%0A%20%20%20%20curr%20%3D%20now.strftime(%22%25Y-%25m-%25d%2C%20%25I%3A%25M%3A%25S%20%25p%20%25Z%22)%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20%23%20Week%20-%202%0A%0A%20%20%20%20**Submission%20Date%3A**%20%60This%20assignment%20will%20not%20be%20graded%20and%20is%20only%20for%20practice.%60%0A%0A%20%20%20%20**Last%20Updated%3A**%20%60%7Bcurr%7D%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20return%20np%2C%20pd%0A%0A%0A%40app.cell%0Adef%20_(pd)%3A%0A%20%20%20%20df%20%3D%20pd.read_csv(%22Week-2%2FPractice%20Assignment%2Fdataset.csv%22)%0A%20%20%20%20return%20(df%2C)%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.info()%0A%20%20%20%20df.head()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%201%0A%0A%20%20%20%20How%20many%20samples%20are%20there%20in%20this%20dataset%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.shape%5B0%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%202%0A%0A%20%20%20%20How%20many%20input%20features%20are%20there%20in%20this%20dataset%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20df.shape%5B1%5D%20-%201%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%203%0A%0A%20%20%20%20What%20type%20of%20problem%20is%20this%3F%0A%20%20%20%20%3E%20**Hint%3A**%20look%20at%20the%20target%20variable.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20print(%22Classification%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%204%0A%0A%20%20%20%20Which%20of%20the%20features%20has%20least%20variance%3F%0A%20%20%20%20%3E%20**Hint%3A**%20Ignore%2Fremove%20missing%20values%20if%20any.%20Are%20there%20any%20categorical%20features%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20np%2C%20pd)%3A%0A%20%20%20%20df.replace(%22%3F%22%2C%20np.nan).iloc%5B%3A%2C%20%3A4%5D.apply(pd.to_numeric%2C%20errors%3D%22coerce%22).var(%0A%20%20%20%20%20%20%20%20skipna%3DTrue%0A%20%20%20%20).idxmin()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%205%0A%0A%20%20%20%20Which%20of%20the%20following%20features%20has%20least%20number%20of%20outliers%3F%0A%20%20%20%20%3E%20**Hint%3A**%20Which%20visualization%20marks%20outliers%3F%20Ignore%2Fremove%20missing%20values%20if%20any%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20pd)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%0A%20%20%20%20df2%20%3D%20df.copy()%0A%20%20%20%20for%20_col%20in%20%5B%22V1%22%2C%20%22V2%22%5D%3A%0A%20%20%20%20%20%20%20%20df2%5B_col%5D%20%3D%20pd.to_numeric(df2%5B_col%5D%2C%20errors%3D%22coerce%22)%0A%0A%20%20%20%20fig%2C%20axes%20%3D%20plt.subplots(2%2C%202%2C%20figsize%3D(12%2C%2010))%0A%20%20%20%20fig.suptitle(%22Box%20Plots%20for%20All%20Numerical%20Features%22%2C%20fontsize%3D16)%0A%0A%20%20%20%20cols_to_plot%20%3D%20%5B%22V1%22%2C%20%22V2%22%2C%20%22V3%22%2C%20%22V4%22%5D%0A%20%20%20%20for%20ax%2C%20_col%20in%20zip(axes.flatten()%2C%20cols_to_plot)%3A%0A%20%20%20%20%20%20%20%20ax.boxplot(df2%5B_col%5D.dropna())%0A%20%20%20%20%20%20%20%20ax.set_title(f%22Box%20Plot%20of%20%7B_col%7D%22)%0A%20%20%20%20%20%20%20%20ax.set_ylabel(_col)%0A%0A%20%20%20%20plt.tight_layout(rect%3D%5B0%2C%200.03%2C%201%2C%200.95%5D)%0A%20%20%20%20fig%0A%20%20%20%20return%20(df2%2C)%0A%0A%0A%40app.cell%0Adef%20_(df2)%3A%0A%20%20%20%20outlier_counts%20%3D%20%7B%7D%0A%20%20%20%20for%20_col%20in%20%5B%22V1%22%2C%20%22V2%22%2C%20%22V3%22%2C%20%22V4%22%5D%3A%0A%20%20%20%20%20%20%20%20data_col%20%3D%20df2%5B_col%5D.dropna()%0A%0A%20%20%20%20%20%20%20%20Q1%20%3D%20data_col.quantile(0.25)%0A%20%20%20%20%20%20%20%20Q3%20%3D%20data_col.quantile(0.75)%0A%20%20%20%20%20%20%20%20IQR%20%3D%20Q3%20-%20Q1%0A%0A%20%20%20%20%20%20%20%20lower_bound%20%3D%20Q1%20-%201.5%20*%20IQR%0A%20%20%20%20%20%20%20%20upper_bound%20%3D%20Q3%20%2B%201.5%20*%20IQR%0A%0A%20%20%20%20%20%20%20%20outlier_counts%5B_col%5D%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20(data_col%20%3C%20lower_bound)%20%7C%20(data_col%20%3E%20upper_bound)%0A%20%20%20%20%20%20%20%20).sum()%0A%0A%20%20%20%20print(%22Number%20of%20outliers%20in%20each%20feature%3A%22)%0A%20%20%20%20for%20feature%2C%20count%20in%20outlier_counts.items()%3A%0A%20%20%20%20%20%20%20%20print(f%22%5Ct-%20%7Bfeature%7D%3A%20%7Bcount%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%206%0A%0A%20%20%20%20Which%20of%20the%20following%20is%20true%20about%20target%20variable%3F%0A%0A%20%20%20%20-%20%5B%20%5D%20It%20has%20higher%20'YES'%20entries%20than%20'NO'%20entries.%0A%20%20%20%20-%20%5Bx%5D%20It%20has%20higher%20'NO'%20entries%20than%20'YES'%20entries.%0A%20%20%20%20-%20%5B%20%5D%20It%20has%20same%20number%20of%20entries%20of%20'YES'%20and%20'NO'%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20(df%5B%22Target%22%5D%20%3D%3D%20%22YES%22).sum()%2C%20(df%5B%22Target%22%5D%20%3D%3D%20%22NO%22).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%207%0A%0A%20%20%20%20How%20many%20features%20have%20missing%20values%20in%20the%20dataset%3F%0A%20%20%20%20%3E%20**Hint%3A**%20missing%20values%20are%20marked%20by%20'%3F'%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20((df%20%3D%3D%20%22%3F%22).sum()%20%3E%200).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%208%0A%0A%20%20%20%20What%20is%20total%20number%20of%20missing%20values%20in%20the%20dataset%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df)%3A%0A%20%20%20%20(df%20%3D%3D%20%22%3F%22).sum().sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%209%0A%0A%20%20%20%20What%20is%20average%20of%20first%20feature%20(i.e.%20'V1')%20after%20applyting%20SimpleImputer(strategy%20%3D%20'median')%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20np%2C%20pd)%3A%0A%20%20%20%20from%20sklearn.impute%20import%20SimpleImputer%0A%0A%20%20%20%20V1_series%20%3D%20pd.to_numeric(df%5B%22V1%22%5D.replace(%22%3F%22%2C%20np.nan)%2C%20errors%3D%22coerce%22)%0A%0A%20%20%20%20_imputer%20%3D%20SimpleImputer(strategy%3D%22median%22)%0A%20%20%20%20round(_imputer.fit_transform(V1_series.values.reshape(-1%2C%201)).mean()%2C%203)%0A%20%20%20%20return%20SimpleImputer%2C%20V1_series%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%2010%0A%0A%20%20%20%20What%20is%20average%20of%20first%20column%20after%20applyting%20KNNImputer(n_neighbors%20%3D%203)%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(V1_series)%3A%0A%20%20%20%20from%20sklearn.impute%20import%20KNNImputer%0A%0A%20%20%20%20_imputer%20%3D%20KNNImputer(n_neighbors%3D3)%0A%20%20%20%20round(_imputer.fit_transform(V1_series.values.reshape(-1%2C%201)).mean()%2C%203)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%2011%0A%0A%20%20%20%20What%20is%20average%20of%20second%20feature%20(i.e.%20'V2')%20after%20applyting%20SimpleImputer(strategy%20%3D%20'mean')%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(SimpleImputer%2C%20df%2C%20np%2C%20pd)%3A%0A%20%20%20%20V2_series%20%3D%20pd.to_numeric(df%5B%22V2%22%5D.replace(%22%3F%22%2C%20np.nan)%2C%20errors%3D%22coerce%22)%0A%0A%20%20%20%20_imputer%20%3D%20SimpleImputer(strategy%3D%22mean%22)%0A%20%20%20%20round(_imputer.fit_transform(V2_series.values.reshape(-1%2C%201)).mean()%2C%203)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
e75f6eff4e69e03674edbfad01507ade92e2a3e3d4b834484c501392f1e5f59d